import Vue from 'vue'
import VueRouter from 'vue-router'
import HomeView from '../views/HomeView.vue'
import LoginView from '../views/LoginView.vue'
import BackgroundView from '../views/BackgroundView.vue'
import BookListView from '../views/BookListView.vue'
import BookCreate from '../views/BookCreate.vue'
import LoginUpdate from '../views/LoginUpdate.vue'
import BookDetail from '../views/BookDetailView'
import Home from '../views/Home.vue'
import Homea from '../views/Homea.vue'
import ProgramView from '../views/ProgramView.vue'
import ProgramDetailView from "../views/ProgramDetailView.vue"
import ProgramCreate from "../views/ProgramCreateView.vue"
import Publish from "../views/PublishCreateView.vue"
import Project from "../views/ProjectView.vue"
import Register from "../views/RegisterView.vue"
import Registerview from "../views/RegisterDetailView.vue"
Vue.use(VueRouter)

const routes = [
  {
    path: '/home',
    name: 'home',
    component: HomeView,
    meta: {
      title: '主页'
    }
  },
  {
    path: '/',
    redirect: 'homeaaa',

  },
  {
    path: '/homeaaa',
    name: 'homeaaa',
    component: Home,

  },
  {
    path: '/login',
    name: 'login',
    component: LoginView,
    meta: {
      title: '登入'
    }
    // meta:{
    //   TabbarShow:true
    // }
  },
  {
    path: '/back',
    name: 'back',
    component: BackgroundView,
    meta: {
      title: '后端管理系统主页'
    }
    // meta:{
    //   TabbarShow:true
    // }
  },
  {
    path: '/booklist',
    name: 'booklist',
    component: BookListView,
    meta: {
      title: '后端管理系统证书列表'
    }
    // meta:{
    //   TabbarShow:true
    // }
  },
  {
    path: '/booklist/create',
    name: 'booklist-create',
    component: BookCreate,
    meta: {
      title: '创建证书'
    }
  },
  {
    path: '/loginUpdate',
    name: 'loginUpdate',
    component: LoginUpdate,
    meta: {
      title: '修改密码'
    }
  },
  {
    path: '/bookDetail/:cid',
    name: 'bookDetail',
    component: BookDetail,
    meta: {
      title: '证书详情页'
    }
  },
  {
    path: '/program',
    name: 'program',
    component: ProgramView,
    meta: {
      title: '项目计划汇总表'
    },


  },
  {
    path: "/programdetail/:cid",
    name: "programdetail",
    component: ProgramDetailView,
    meta: {
      title: '项目计划汇总详情页'
    }
  },
  {
    path: "/programCreate",
    name: "programCreate",
    component: ProgramCreate,
    meta: {
      title: '创建项目计划'
    }
  },
  {
    path: "/publishCreate/:cid",
    name: "publishCreate",
    component: Publish,
    meta: {
      title: '创建修改发布汇总列表'
    }
  },
  {
    path: "/project/:cid",
    name: "project",
    component: Project,
    meta: {
      title: '创建修改立项汇总列表'
    }
  },
  {
    path: "/register",
    name: "register",
    component: Register,
    meta: {
      title: '证书领取列表'
    }
  },
  {
    path: "/registerview/:cid",
    name: "registerview",
    component: Registerview,
    meta: {
      title: '创建修改证书领取列表'
    }
  },

  {
    path: '/homeaaaa',
    name: 'homeaaaa',
    component: Homea,
  }


]




const router = new VueRouter({
  // mode: 'history',
  routes
})
router.beforeEach((to, from, next) => {
  const token = localStorage.getItem('e_token')
  if (to.name !== 'login' && !token)
    next({ name: 'login' })
  else next()
  if (to.meta.title) {
    document.title = to.meta.title
  }
  next()
})

export default router
